const redisClient = require('../../libs/Redis/redisClient').client;
const _ = require('underscore');
const moment = require('moment');

async function pushCalibrationData(meter) {
    try {
        let deviceNo = meter.deviceNo;
        let dataList = JSON.parse(meter.data);
        let data = {currentTime: moment().format('YYYY-MM-DD HH:mm:ss'), dataList: dataList};
        let currentDate = moment().format('YYYY-MM-DD');
        let meterKeyId = `${deviceNo}-calibration-${currentDate}`;
        let dataObjStr = JSON.stringify(data);
        redisClient.rpush(meterKeyId, dataObjStr, redisClient.print);
    } catch (e) {
        console.log(e);
    }
}

exports.pushCalibrationData = pushCalibrationData;